package com.qing.expert.modules.admin.controller;

import com.qing.expert.common.annotation.OperationLog;
import com.qing.expert.common.response.R;
import com.qing.expert.modules.admin.service.AdminUserService;
import com.qing.expert.modules.admin.vo.request.UserRoleRequest;
import com.qing.expert.modules.admin.vo.request.UserStatusRequest;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/admin/users")
public class AdminUserController {

    @Resource
    private AdminUserService adminUserService;

    /**
     * 禁用/启用账号
     */
    @OperationLog(action = "update_user_status", detail = "修改用户状态: #{#userId}, 状态: #{#request.status}")
    @PutMapping("/{userId}/status")
    public R<Void> updateUserStatus(
            @PathVariable String userId,
            @Validated @RequestBody UserStatusRequest request) {
        adminUserService.updateUserStatus(userId, request.getStatus());
        return R.ok();
    }

    /**
     * 修改用户角色
     */
    @OperationLog(action = "update_user_role", detail = "修改用户角色: #{#userId}, 角色: #{#request.role}")
    @PutMapping("/{userId}/role")
    public R<Void> updateUserRole(
            @PathVariable String userId,
            @Validated @RequestBody UserRoleRequest request) {
        adminUserService.updateUserRole(userId, request.getRole());
        return R.ok();
    }
}